package basic.io;

import java.io.*;


public class CopyMultyFolder {

	public static void main(String[] args) throws IOException {
		File srcFile = new File("F:\\demo");
		File targetFile = new File("D:\\");
		copyFolder(srcFile,targetFile);
}
	
	
//
	public  static void copyFolder(File srcFile, File targetFile) throws IOException {
		if (srcFile.isDirectory()) {
			File newfolder = new File(targetFile, srcFile.getName());//demo--F:\\demo
			newfolder.mkdir();
			File[] files = srcFile.listFiles();
			for(File fileTemp:files){
				copyFolder(fileTemp, newfolder);	
			}             //frame.avi  D://demo
		}
		else{                                   
			File newFile = new File(targetFile,srcFile.getName());
			copyFile(srcFile,newFile);
			
		}

	}

	public static void copyFile(File file, File newFile) throws IOException {
		BufferedInputStream bis = new BufferedInputStream(new FileInputStream(file));
		BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(newFile));

		byte[] by = new byte[1024];
		int len;
		while ((len = bis.read(by)) != -1) {
			bos.write(by, 0, len);
		}

		bis.close();
		bos.close();

	}

}
